package com.soso.base.filter;

import java.io.IOException;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;

import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpServletResponseWrapper;

public class ETagResponseWrapper extends HttpServletResponseWrapper
{
   private HttpServletResponse response = null;
   private ServletOutputStream stream   = null;
   private PrintWriter         writer   = null;
   private OutputStream        buffer   = null;

   public ETagResponseWrapper( HttpServletResponse response, OutputStream buffer )
   {
      super( response );
      this.response = response;
      this.buffer = buffer;
   }

   public ServletOutputStream getOutputStream() throws IOException
   {
      if( stream == null )
         stream = new ETagResponseStream( response, buffer );
      return stream;
   }

   public PrintWriter getWriter() throws IOException
   {
      if( writer == null )
         writer = new PrintWriter( new OutputStreamWriter( getOutputStream(), "UTF-8" ) );

      return writer;
   }

   public void flushBuffer() throws IOException
   {
      stream.flush();
   }
}